﻿@{
    ViewBag.Title = "AddDamage";
}

<div class="mini-fit" style="height:100%;">
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 47%;"
        url="GetGoodsDetail?TruckID=@ViewBag.TruckID"  showpager="false"
        allowcelledit="true" allowcellselect="true" multiselect="true"
        editnextonenterkey="true" editnextrowcell="true">
        <div property="columns">
            <div type="indexcolumn" field="OrderID"></div>
            <div type="checkcolumn" field="DetailID"></div>
             <div field="GoodsNum"  headeralign="center" >
                货号
            </div>
             <div field="GoodsName"  headeralign="center" >
                货物名称
            </div>
            <div field="Quantity"  headeralign="center" >
                件数
            </div>
             <div field="ReceiverLinkman"  headeralign="center" >
                收货人
            </div>
            <div field="SenderLinkman"  headeralign="center" >
                发货人
            </div>
        </div>
    </div>

    <a id="add" class="mini-button" iconcls="icon-add" plain="true" onclick="addRow()">增加</a>
    <a id="delete" class="mini-button" iconcls="icon-remove" plain="true" onclick="removeRow()">删除</a>
<a id="edit" class="mini-button" iconcls="icon-save" plain="true" onclick="saveData()">保存</a>

    <div id="datagrid2" class="mini-datagrid" style="width: 100%; height: 47%;"
          showpager="false"
        allowcelledit="true" allowcellselect="true" multiselect="true"
        editnextonenterkey="true" editnextrowcell="true">
        <div property="columns">
            <div type="indexcolumn" field="OrderID"></div>
            <div type="checkcolumn" field="DetailID"></div>
             <div field="GoodsNum"  headeralign="center" >
                货号
            </div>
             <div field="GoodsName"  headeralign="center" >
                货物名称
            </div>
            <div field="Quantity"  headeralign="center" >
                件数<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
             <div field="ReceiverLinkman"  headeralign="center" >
                收货人
            </div>
            <div field="SenderLinkman"  headeralign="center" >
                发货人
            </div>
            <div field="DamageQuantity"  headeralign="center" >
                损坏件数<input property="editor" class="mini-textbox" style="width: 100%;" /> 
            </div>
             <div field="LostQuantity"  headeralign="center" >
                丢失件数<input property="editor" class="mini-textbox" style="width: 100%;" /> 
            </div>
            <div field="RamageRemark"  headeralign="center" >
                损坏程度<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
             <div field="ResponsibleMan"  headeralign="center" >
                负责人<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="ReparationsAmount"  headeralign="center" >
                赔偿金额<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="FollowUpRemark"  headeralign="center" >
                跟进说明<input property="editor" class="mini-area" style="width: 100%;" />
            </div>
        </div>
    </div>

</div>




<script type="text/javascript">

    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load({
        fail: function () {
        }
    });

    var gridSave = mini.get("datagrid2");

    function addRow() {
        grid.validate();
        if (grid.isValid() == false) {
            var error = grid.getCellErrors()[0];
            grid.beginEditCell(error.record, error.column);
            return;
        }

        var rows = grid.getSelecteds();
        if (rows.length < 1) {
            alert("请选择货物！");
            return;
        }

        for (var i = 0; i < rows.length; i++) {
            var obj = rows[i];
            var newRow = { name: "New Row" };

            newRow.OrderID = obj.OrderID;
            newRow.DetailID = obj.DetailID;
            newRow.GoodsNum = obj.GoodsNum;
            newRow.GoodsName = obj.GoodsName;
            newRow.Quantity = obj.Quantity;
            newRow.ReceiverLinkman = obj.ReceiverLinkman;
            newRow.SenderLinkman = obj.SenderLinkman;

            gridSave.addRow(newRow, 0);
            gridSave.beginEditCell(newRow, "DKey");

        }

       
    }
    function removeRow() {
        var rows = gridSave.getSelecteds();
        if (rows.length > 0) {
            gridSave.removeRows(rows, true);
        }
    }

    function saveData() {

        gridSave.validate();
        if (gridSave.isValid() == false) {
            var error = gridSave.getCellErrors()[0];
            gridSave.beginEditCell(error.record, error.column);
            return;
        }

        var added = gridSave.getChanges("added");
        var jsonAdd = mini.encode(added);

        var modified = gridSave.getChanges("modified");
        var jsonEdit = mini.encode(modified);

        var removed = gridSave.getChanges("removed");
        var jsonDel = mini.encode(removed);

        gridSave.loading("保存中，请稍后......");
        $.ajax({
            url: "SaveDamage",
            data: { add: jsonAdd, edit: jsonEdit, del: jsonDel },
            type: "post",
            success: function (text, flag, res) {
                gridSave.unmask();
                if (res.responseText == "") {
                    gridSave.reload();
                }
                else
                    top.mini.alert(res.responseText);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.alert(errorThrown.responseText);
            }
        });
    }
</script>

